
*------------------------------PLEASE READ-------------------------------------*
/*
REPLICATION FILE FOR TABLE D1-D4 and Figure D1
AUTHOR: ZHENHUAN LEI & YISHUANG LI
DATE: 11/13/2023
SOFTWARE: STATA 17 SE OPERATED ON WINDOWS 11

STATA PACKAGE NEEDED: 
	ssc install estout, replace 
	ssc install winsor2
	ssc install interflex
*/



*-------------------------- Set up the environment ---------------------------*

clear
set matsize 11000
set more off
use ../data/fiscal_dependence.dta
xtset city_id year

*** Generating variables 
	foreach x in ln_population_hr_c gdp_growth_c ln_city_total_ipo ln_tax_vadded_c ln_investment_fixed_c ln_unemployment_c gdp_secondary_c gdp_tertiary_c {
   gen `x'_2 = L.`x'
}

	gen non_mi = (L.gdp_percapita_c != . & L.population_hr_c != . & L.publicfinance_income_c != . & L.gdp_growth_c != . & L.city_total_ipo !=. & L.tax_vadded_c != . & L.investment_fixed_c != . & L.population_unemployed_c != . & L.gdp_secondary_c != . & L.gdp_tertiary_c != . & L.publicfinance_expenditure_c != .)
	
	gen gdp_capita_14a = .
	replace gdp_capita_14a = ln_gdp_percapita_c if year == 2014
	bysort city_id: egen gdp_capita_14 = min(gdp_capita_14a)

	gen publicfinance_capita_14a = .
	replace publicfinance_capita_14a = ln_per_publicfinance_income_c if year == 2014
	bysort city_id: egen publicfinance_capita_14 = min(publicfinance_capita_14a)

*** Define control variables ***	

	global cont_city L.ln_population_hr_c L.ln_gdp_percapita_c L.ln_per_publicfinance_income_c L.gdp_growth_c L.ln_city_total_ipo L.ln_tax_vadded_c L. ln_investment_fixed_c L.ln_unemployment_c L.gdp_secondary_c L.gdp_tertiary_c L. ln_per_publicfinance_exp_c  

	global cont_city2  L.ln_population_hr_c L.gdp_growth_c L.ln_city_total_ipo L.ln_tax_vadded_c L.ln_investment_fixed_c L.ln_unemployment_c L.gdp_secondary_c L.gdp_tertiary_c  

	global cont_city3 ln_population_hr_c_2 gdp_growth_c_2 ln_city_total_ipo_2  ln_tax_vadded_c_2 ln_investment_fixed_c_2 ln_unemployment_c_2 gdp_secondary_c_2 gdp_tertiary_c_2 

	global pro_cont L.pro_pop L.pro_gdp_percapita L.pro_rev_percapita L.pro_exp_percapita L.pro_growth L.pro_unemp L.rev_vat L.total_ipo 

*-------------------------- Regression analysis -------------------------------*

***Table D1***

	eststo clear
	eststo: qui xtreg ln_income_total centralize_city50 i.pro_code##i.year $cont_city if merge_basiccourt == 0, fe vce(cluster city_id)   
	eststo: qui xtreg ln_exp_total centralize_city50 i.pro_code##i.year $cont_city if merge_basiccourt == 0, fe vce(cluster city_id)   
	eststo: qui xtreg ln_exp_salary centralize_city50 i.pro_code##i.year $cont_city if merge_basiccourt == 0, fe vce(cluster city_id)   
	eststo: qui xtreg ln_other_bene centralize_city50 i.pro_code##i.year $cont_city if merge_basiccourt == 0, fe vce(cluster city_id)  
	eststo: qui xtreg ln_exp_trial centralize_city50 i.pro_code##i.year $cont_city if merge_basiccourt == 0, fe vce(cluster city_id)
	eststo: qui xtreg ln_exp_enforce centralize_city50 i.pro_code##i.year $cont_city if merge_basiccourt == 0, fe vce(cluster city_id)
	esttab, se b(3) t(3) scalars(N_clust) star(* 0.1 ** 0.05 *** 0.01) keep(centralize_city50) 

***Table D2***

	eststo clear
	eststo: qui xtreg ln_income_total centralize_city50##c.gdp_capita_14 $cont_city2 i.pro_code##i.year if merge_basiccourt == 0, fe vce(cluster city_id) 
	eststo: qui xtreg ln_income_total centralize_city50##c.publicfinance_capita_14 $cont_city2 i.pro_code##i.year if merge_basiccourt == 0, fe vce(cluster city_id) 
	eststo: qui xtreg ln_exp_total centralize_city50##c.gdp_capita_14 $cont_city2 i.pro_code##i.year if merge_basiccourt == 0, fe vce(cluster city_id) 
	eststo: qui xtreg ln_exp_total centralize_city50##c.publicfinance_capita_14 $cont_city2 i.pro_code##i.year if merge_basiccourt == 0, fe vce(cluster city_id) 
	esttab, se b(3) t(3) scalars(N_clust) star(* 0.1 ** 0.05 *** 0.01) keep(1.centralize_city50*) replace

***FigureD1***

	eststo clear
	interflex ln_income_total centralize_city50 gdp_capita_14 $cont_city3 if merge_basiccourt == 0, fe(city_id pro_year) cluster (city_id) type(binning) saving(../result/Graph1.jpg) xlabel("Moderator: GDP per capita(log)") dlabel("Reform") ylabel("Court Revenue")
	interflex ln_income_total centralize_city50 publicfinance_capita_14 $cont_city3 if merge_basiccourt == 0, fe(city_id pro_year)  cluster (city_id) type(binning) saving(../result/Graph2.jpg) xlabel("Moderator: Fiscal Revenue per capita(log)") dlabel("Reform") ylabel("Court Revenue")
	interflex ln_exp_total centralize_city50 gdp_capita_14 $cont_city3 if merge_basiccourt == 0, fe(city_id pro_year) cluster (city_id) type(binning) saving(../result/Graph3.jpg) xlabel("Moderator: GDP per capita(log)") dlabel("Reform") ylabel("Court Spending")
	interflex ln_exp_total centralize_city50 publicfinance_capita_14 $cont_city3 if merge_basiccourt == 0, fe(city_id pro_year)  cluster (city_id) type(binning) saving(../result/Graph4.jpg) xlabel("Moderator: Fiscal Revenue per capita(log)") dlabel("Reform") ylabel("Court Spending")



***Table D3***

    winsor2 exp_ratio, replace cut (0 99.9) trim // drop the extreme value
	eststo clear
	eststo: qui reg exp_ratio centralize_city50 if merge_basiccourt == 0 & non_mi , vce(cluster city_id)   
	eststo: qui xtreg exp_ratio centralize_city50 i.pro_code##i.year if merge_basiccourt == 0 & non_mi, fe vce(cluster city_id) 
	eststo: qui xtreg exp_ratio centralize_city50 $cont_city i.pro_code##i.year if merge_basiccourt == 0 & non_mi, fe vce(cluster city_id) 
	esttab, se b(3) t(3) scalars(N_clust) star(* 0.1 ** 0.05 *** 0.01) keep(centralize_city50) replace
 

***Table D4*** 

	eststo clear
	eststo: qui xtreg lexp_edu centralize_city50  $pro_cont i.year i.pro_code if year >= 2014, fe cluster(pro_code)
	eststo: qui xtreg lexp_rd centralize_city50  $pro_cont i.year i.pro_code  if year >= 2014,  cluster(pro_code)
	eststo: qui xtreg lexp_culture centralize_city50  $pro_cont i.year i.pro_code  if year >= 2014, cluster(pro_code) 
	eststo: qui xtreg lexp_env centralize_city50  $pro_cont i.year i.pro_code  if  year >= 2014,  cluster(pro_code)
	eststo: qui xtreg lexp_npc centralize_city50  $pro_cont i.year i.pro_code  if  year >= 2014,  cluster(pro_code)
	eststo: qui xtreg lexp_ps centralize_city50  $pro_cont i.year i.pro_code  if  year >= 2014,  cluster(pro_code)  
	esttab , se b(3) t(3) star(* 0.1 ** 0.05 *** 0.01) keep(centralize_city50) replace
